package labox.innovation.gameserver.model.actor;

import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.model.actor.knownlist.PlayableKnownList;
import labox.innovation.gameserver.model.actor.stat.PlayableStat;
import labox.innovation.gameserver.model.actor.status.PlayableStatus;
import labox.innovation.gameserver.model.quest.QuestState;
import labox.innovation.gameserver.templates.chars.CharTemplate;

/**
 * This class represents all Playable characters in the world.<BR><BR>
 *
 * L2PlayableInstance :<BR><BR>
 * <li>L2PcInstance</li>
 * <li>L2Summon</li><BR><BR>
 *
 */

public abstract class L2Playable extends L2Character {

	private L2Character _lockedTarget;

	/**
	 * Constructor of L2PlayableInstance (use L2Character constructor).<BR><BR>
	 *
	 * <B><U> Actions</U> :</B><BR><BR>
	 * <li>Call the L2Character constructor to create an empty _skills slot and link copy basic Calculator set to this L2PlayableInstance </li><BR><BR>
	 *
	 * @param objectId Identifier of the object to initialized
	 * @param template The L2CharTemplate to apply to the L2PlayableInstance
	 *
	 */
	public L2Playable(long objectId, CharTemplate template) {
		super(objectId, template);
		setIsInvul(false);
	}

	@Override
	public PlayableKnownList getKnownList() {
		return (PlayableKnownList) _knownList;
	}

	@Override
	public void initKnownList() {
		setKnownList(new PlayableKnownList(this));
	}

	@Override
	public PlayableStat getStat() {
		return (PlayableStat) _stat;
	}

	@Override
	public void initCharStat() {
		setStat(new PlayableStat(this));
	}

	@Override
	public PlayableStatus getStatus() {
		return (PlayableStatus) _status;
	}

	@Override
	public void initCharStatus() {
		setStatus(new PlayableStatus(this));
	}

	@Override
	public boolean doDie(L2Character killer) {
		if (!super.doDie(killer))
			return false;
		// Notify Quest of L2Playable's death
		FuzePcInstance actingPlayer = getActingPlayer();
		for (QuestState qs : actingPlayer.getNotifyQuestOfDeath()) {
			qs.getQuest().notifyDeath((killer == null ? this : killer), this, qs);
		}

		FuzePcInstance player = killer.getActingPlayer();

		if (player != null)
			player.onKillUpdatePvPKarma(this);
		return true;
	}

	public boolean checkIfPvP(L2Character target) {
		if (target == null)
			return false; // Target is null
		if (target == this)
			return false; // Target is self
		if (!(target instanceof L2Playable))
			return false; // Target is not a L2PlayableInstance

		FuzePcInstance player = null;
		if (this instanceof FuzePcInstance)
			player = (FuzePcInstance) this;
		else if (this instanceof L2Summon)
			player = ((L2Summon) this).getOwner();

		if (player == null)
			return false; // Active player is null
		if (player.getKarma() != 0)
			return false; // Active player has karma

		FuzePcInstance targetPlayer = null;
		if (target instanceof FuzePcInstance)
			targetPlayer = (FuzePcInstance) target;
		else if (target instanceof L2Summon)
			targetPlayer = ((L2Summon) target).getOwner();

		if (targetPlayer == null)
			return false; // Target player is null
		if (targetPlayer == this)
			return false; // Target player is self
		if (targetPlayer.getKarma() != 0)
			return false; // Target player has karma
		if (targetPlayer.getPvpFlag() == 0)
			return false;

		return true;
	}

	/**
	 * Return True.<BR><BR>
	 */
	@Override
	public boolean isAttackable() {
		return true;
	}

	public boolean isLockedTarget() {
		return _lockedTarget != null;
	}

	public L2Character getLockedTarget() {
		return _lockedTarget;
	}

	public void setLockedTarget(L2Character cha) {
		_lockedTarget = cha;
	}

	/** 
	 * 设置角色的基础力量
	 * @return
	 */
	public final void setAssignedSTR(int str) {
		getStat().setAssignedSTR(str);
	}

	/** 
	 * 设置角色的基础敏捷值
	 * @return
	 */
	public final void setAssignedDEX(int dex) {
		getStat().setAssignedDEX(dex);
	}

	/** 
	 * 设置角色的基础智力值
	 * @return
	 */
	public final void setAssignedINT(int INT) {
		getStat().setAssignedINT(INT);
	}

	/** 
	 * 设置角色的基础精神值
	 * @return
	 */
	public final void setAssignedMEN(int men) {
		getStat().setAssignedMEN(men);
	}

	/** 
	 * 设置角色的基础体质
	 * @return
	 */
	public final void setAssignedCON(int con) {
		getStat().setAssignedCON(con);
	}
	
	/** 
	 * 获得角色的基础力量
	 * @return
	 */
	public final int getAssignedSTR() {
		return getStat().getAssignedSTR();
	}

	/** 
	 * 获得角色的基础敏捷值
	 * @return
	 */
	public final int getAssignedDEX() {
		return getStat().getAssignedDEX();
	}

	/** 
	 * 获取角色的基础智力值
	 * @return
	 */
	public final int getAssignedINT() {
		return getStat().getAssignedINT();
	}

	/** 
	 * 获得角色的基础精神值
	 * @return
	 */
	public final int getAssignedMEN() {
		return getStat().getAssignedMEN();
	}

	/** 
	 * 获得角色的基础体质
	 * @return
	 */
	public final int getAssignedCON() {
		return getStat().getAssignedCON();
	}
	
	/** 
	 * 获得未分配的点数
	 * @return
	 */
	public final int getUnassignedPoint() {
		return getStat().getUnassignedPoint();
	}
}
